//
//  KHHStoryItemCollectionViewCell.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "KHHStoryItemCollectionViewCell.h"
#import "UIImageView+WebCache.h"


@interface KHHStoryItemCollectionViewCell ()

@property (nonatomic, retain) UIImageView *coverImg;
@property (nonatomic, retain) UILabel *titleLable;
@property (nonatomic, retain) UIImageView *photoImg;
@property (nonatomic, retain) UILabel *nameLable;
@property (nonatomic, retain) UILabel *location;
@property (nonatomic, retain) UIImageView *img; //阴影
@property (nonatomic, retain) UILabel *label;
@end

@implementation KHHStoryItemCollectionViewCell

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.label = [[UILabel alloc] init];
        self.label.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.label];
        
        self.coverImg = [[UIImageView alloc] init];
        [self.contentView addSubview:self.coverImg];
        self.coverImg.contentMode = UIViewContentModeScaleAspectFill;
        self.coverImg.clipsToBounds = YES;
        self.contentView.layer.masksToBounds = YES;
        self.contentView.layer.cornerRadius = 6;
        
        self.img = [[UIImageView alloc] init];
        [self.contentView addSubview:self.img];
        self.img.image = [UIImage imageNamed:@"jiabian2"];
        self.img.frame = CGRectMake(0, 0, (self.frame.size.width - 30) / 2, 150);
        [self.contentView addSubview:self.img];
        
        self.location = [[UILabel alloc]init];
        [self.coverImg addSubview:self.location];
        self.location.font = [UIFont fontWithName:@"Arial" size:11];
        //self.location.shadowColor = [UIColor blackColor];
        
        self.titleLable = [[UILabel alloc]init];
        self.titleLable.numberOfLines = 2;
        self.titleLable.textColor = [UIColor darkGrayColor];
        self.titleLable.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.titleLable];
        
        self.photoImg = [[UIImageView alloc]init];
        self.photoImg.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        [self.contentView addSubview:self.photoImg];
        
        self.nameLable = [[UILabel alloc]init];
        self.nameLable.font = [UIFont systemFontOfSize:10];
        self.nameLable.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:self.nameLable];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    
    self.label.frame = self.contentView.frame;
    self.coverImg.frame = CGRectMake(0, 0, layoutAttributes.size.width, 150);
    self.location.frame = CGRectMake(10, self.coverImg.frame.size.height - 10 - 15, self.coverImg.frame.size.width - 20, 15);
    self.titleLable.frame = CGRectMake(10, self.coverImg.frame.size.height + 15, self.coverImg.frame.size.width - 20, 30);
    self.photoImg.frame = CGRectMake(10, self.titleLable.frame.origin.y + self.titleLable.frame.size.height + 15,25 , 25);
    self.photoImg.layer.masksToBounds = YES;
    self.photoImg.layer.cornerRadius = self.photoImg.frame.size.width / 2;
    self.nameLable.frame = CGRectMake(10 + 25 + 10, self.photoImg.frame.origin.y + 5, 100, 15);
    
//    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"isNight"]) {
//        self.contentView.backgroundColor = [UIColor blackColor];
//        self.titleLable.textColor = [UIColor whiteColor];
//        self.nameLable.textColor = [UIColor whiteColor];
//        self.coverImg.backgroundColor = [UIColor blackColor];
//        self.location.textColor = [UIColor whiteColor];
//        
//    }else
//    {
//        self.contentView.backgroundColor = [UIColor whiteColor];
//        self.titleLable.textColor = [UIColor darkGrayColor];
//        self.nameLable.textColor = [UIColor darkGrayColor];
//        self.location.textColor = [UIColor whiteColor];
//        self.coverImg.backgroundColor = [UIColor whiteColor];
//    }
}

#pragma mark - 首页故事赋值
- (void)setRecommendModel:(KHHRecommendModel *)recommendModel
{
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:recommendModel.index_cover] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
    self.titleLable.text = recommendModel.index_title;
    self.location.text = recommendModel.poiName;
    //recommendModel.spot_id
}

- (void)setUserModel:(KHHRecommendModel *)userModel
{
    
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:userModel.avatar_m] placeholderImage:nil];
    self.nameLable.text = userModel.name;
    
}

#pragma mark - 全部页赋值
- (void)setStoryAllModel:(KHHRecommendModel *)storyAllModel
{
    
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:storyAllModel.index_cover] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
    self.titleLable.text = storyAllModel.index_title;
    self.location.text = storyAllModel.poiName;
}
- (void)setStoryUserModel:(KHHRecommendModel *)storyUserModel
{
    
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:storyUserModel.index_cover] placeholderImage:nil];
    self.nameLable.text = storyUserModel.name;
}


@end
